<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>机构信息维护</title>
    <script src="../../../resources/app/all.js" type="text/javascript"></script>
    <style type="text/css">
        a:link {
            text-decoration: none;
        }

        a:visited {
            text-decoration: none;
        }

        a:hover {
            text-decoration: none;
        }

        a:active {
            text-decoration: none;
        }
    </style>
</head>
<body class="easyui-layout" data-options="fit:true">
<div data-options="region:'center'" style="padding: 5px;">
    <form class="layui-form layui-form-pane" action="" id="form" lay-filter="example">
        <div class="layui-form-item" id="catalog">
            <label class="layui-form-label">上级机构</label>
            <div class="layui-input-block">
                <input type="text" name="parentName" lay-verify="required" autocomplete="off" placeholder="请输入上级机构"
                       class="layui-input layui-disabled">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">名称</label>
            <div class="layui-input-block">
                <input type="hidden" id="id" name="id">
                <input type="hidden" id="parentId" name="parentId">
                <input type="hidden" id="pids" name="pids">
                <input type="text" name="name" lay-verify="required" autocomplete="off" placeholder="请输入名称"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">负责人</label>
            <div class="layui-input-block">
                <input type="text" name="person" lay-verify="required" autocomplete="off" placeholder="请输入负责人"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">联系电话</label>
            <div class="layui-input-block">
                <input type="text" name="tel" lay-verify="required" autocomplete="off" placeholder="请输入联系电话"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-block">
                <input type="text" name="email" lay-verify="required" autocomplete="off" placeholder="请输入邮箱"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">类型</label>
            <div class="layui-input-block">
                <input type="radio" name="type" value="0" title="公司" checked="true">
                <input type="radio" name="type" value="1" title="部门">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">说明</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" name="remark" class="layui-textarea"></textarea>
            </div>
        </div>
    </form>
</div>
<div data-options="region:'south',border:false">
    <div class="dialog-button">
        <button id="save" class="layui-btn layui-btn-normal">确定</button>
        <button id="cancel" class="layui-btn layui-btn-primary">取消</button>
    </div>
</div>

<script>
    layui.use(['form', 'layedit', 'laydate'], function () {
        const form = layui.form
            , layer = layui.layer;
        let parData = ToolUtil.OpenData();
        if (parData.act == 'edit') {
            let data = parData.data;
            form.val('example', JSON.parse(JSON.stringify(data)));
        } else {
            if (parData.id == 0) {
                form.val('example', {
                    parentName: '/',
                    parentId: 0,
                    pids:0,
                    type: 0
                });
                layui.$(".layui-inline").addClass("layui-hide")
            } else {
                form.val('example', {
                    parentName: parData.data.name,
                    parentId: parData.id,
                    pids:parData.data.pids+"/"+parData.id
                });
            }
        }
        $('#save').on('click', function () {
            if (parData.act === 'add') {
                ToolUtil.POST({
                    url: global.api_url + '/sys/sysDepartment',
                    data: JSON.stringify(ToolUtil.FormJSON("form")),
                    async: false,
                    success: function (obj) {
                        if (obj && obj.code === '00') {
                            saveClear()
                        } else if (obj.code === '98' || obj.code === '97') {
                            location.href = global.loginUrl;
                        } else {
                            layer.alert(obj.msg,{icon:5});
                        }
                    }
                });
            } else {
                ToolUtil.PUT({
                    url: global.api_url + '/sys/sysDepartment',
                    data: JSON.stringify(ToolUtil.FormJSON("form")),
                    async: false,
                    success: function (obj) {
                        if (obj && obj.code === '00') {
                            saveClear()
                        } else if (obj.code === '98' || obj.code === '97') {
                            location.href = global.loginUrl;
                        } else {
                            layer.alert(obj.msg,{icon:5});
                        }
                    }
                });
            }
        });
        $('#cancel').on('click', function () {
            clear()
        });

        function saveClear() {
            parent.location.reload();
            clear();
        }

        function clear() {
            let index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
            layer.close(index);
        }

    });
</script>
</body>
</html>